package com.ruoyi.multab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.multab.domain.MulModelMain;
import com.ruoyi.multab.domain.MulModelParam;
import com.ruoyi.multab.service.IMulModelMainService;
import com.ruoyi.multab.service.IMulModelParamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型参数Controller
 * 
 * @author zhouwc
 * @date 2020-08-10
 */
@Controller
@RequestMapping("/multab/multabparam")
public class MulModelParamController extends BaseController
{
    private String prefix = "multab/multabparam";
    
    @Autowired
    private IMulModelMainService mulModelMainService;
    @Autowired
    private IMulModelParamService mulModelParamService;

    @RequiresPermissions("multab:multabparam:view")
    @GetMapping()
    public String multabparam(MulModelParam mulModelParam, ModelMap mmap)
    {
    	String mainId = mulModelParam.getMainId();
    	MulModelMain selectMulModelMainById = mulModelMainService.selectMulModelMainById(Integer.parseInt(mainId));
        mmap.put("mulModelParam", selectMulModelMainById);

        return prefix + "/multabparam";
    }

    /**
     * 查询模型参数列表
     */
    @RequiresPermissions("multab:multabparam:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(MulModelParam mulModelParam)
    {
        startPage();
        List<MulModelParam> list = mulModelParamService.selectMulModelParamList(mulModelParam);
        return getDataTable(list);
    }

    /**
     * 导出模型参数列表
     */
    @RequiresPermissions("multab:multabparam:export")
    @Log(title = "模型参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MulModelParam mulModelParam)
    {
        List<MulModelParam> list = mulModelParamService.selectMulModelParamList(mulModelParam);
        ExcelUtil<MulModelParam> util = new ExcelUtil<MulModelParam>(MulModelParam.class);
        return util.exportExcel(list, "multabparam");
    }

    /**
     * 新增模型参数
     */
    @GetMapping("/add")
    public String add(String mainId, ModelMap mmap)
    {
    	mmap.put("mainId", mainId);
        return prefix + "/add";
    }

    /**
     * 新增保存模型参数
     */
    @RequiresPermissions("multab:multabparam:add")
    @Log(title = "模型参数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MulModelParam mulModelParam)
    {
        return toAjax(mulModelParamService.insertMulModelParam(mulModelParam));
    }

    /**
     * 修改模型参数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MulModelParam mulModelParam = mulModelParamService.selectMulModelParamById(id);
        mmap.put("mulModelParam", mulModelParam);
        return prefix + "/edit";
    }

    /**
     * 修改保存模型参数
     */
    @RequiresPermissions("multab:multabparam:edit")
    @Log(title = "模型参数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MulModelParam mulModelParam)
    {
        return toAjax(mulModelParamService.updateMulModelParam(mulModelParam));
    }

    /**
     * 删除模型参数
     */
    @RequiresPermissions("multab:multabparam:remove")
    @Log(title = "模型参数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mulModelParamService.deleteMulModelParamByIds(ids));
    }
}
